package thread;

/**
 * 线程的优先级
 * 县城有十个优先级, 分别用整数1-10来表示
 * 其中1位最低优先级, 10位最高优先级, 5位默认优先级
 * 线程无法主动索取时间片, 只能被动被线程调度器分配, 但是优先级越高获取的时间片越大
 * 线程的优先级可以通过setPriority()方法来设置
 */
public class PriorityDemo {
    public static void main(String[] args) {
        Thread m = new Thread(){
            public void run(){
                for(int i=0; i<1000;i++){
                    System.out.println("MAX");
                }
            }
        };
        Thread max = new Thread(m);

        Runnable n = new Runnable(){
            public void run(){
                for(int i = 0; i<1000; i++){
                    System.out.println("MIN");
                }
            }
        };
        Thread min = new Thread(n);

        Thread r = new Thread(()-> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("NORM");
            }
        });
        Thread norm = new Thread(r);

        min.setPriority(Thread.MIN_PRIORITY);
        max.setPriority(Thread.MAX_PRIORITY);

        min.start();
        max.start();
        norm.start();
    }
}
